﻿using System;
namespace Xtee.XteeClient.Calculator {
    using global::Calculator.Xroad.Eu;
    using global::Calculator.Xroad.Eu.Messages;
    using global::Xtee.Core;
    using System.Collections.Generic;
    
    
    public class CalculatorAdapter {
        
        private string _protocolVersion = "4.0";
        
        private Xtee.Core.Client.IXteeCommand _xteeCommand;
        
        public CalculatorAdapter() : 
                this(new Xtee.Core.Client.XteeCommand(new Xtee.Core.Client.Config.Configuration())) {
        }
        
        public CalculatorAdapter(Xtee.Core.Client.IXteeCommand command) {
            this._xteeCommand = command;
        }
        
        public virtual Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType Service {
            get {
                return new Xroad.Eu.Xsd.Identifiers.XRoadServiceIdentifierType(){ObjectType = "SERVICE", XRoadInstance = "EE",MemberClass = "GOV", MemberCode = "700030", SubsystemCode = "Calc"};
            }
        }
        
        public virtual string ProtocolVersion {
            get {
                return this._protocolVersion;
            }
            set {
                this._protocolVersion = value;
            }
        }
        
        public virtual Xtee.Core.Client.IXteeCommand XteeCommand {
            get {
                return this._xteeCommand;
            }
            set {
                this._xteeCommand = value;
            }
        }
        
        public virtual global::Calculator.Xroad.Eu.Messages.HistoryResponse GetHistory(System.DateTime request) {
            var getHistoryInputHeader = new global::Calculator.Xroad.Eu.Headers.GetHistoryInputHeader();
            getHistoryInputHeader.Client = _xteeCommand.Configuration.Client;
            getHistoryInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            getHistoryInputHeader.ProtocolVersion = this.ProtocolVersion;
            getHistoryInputHeader.Service = Service;
            getHistoryInputHeader.Service.ServiceCode = "GetHistory";
            getHistoryInputHeader.Service.ServiceVersion = "v1";
            getHistoryInputHeader.UserId = _xteeCommand.Configuration.UserId;
            getHistoryInputHeader.Issue = _xteeCommand.Configuration.Issue;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("tns", "http://calculator.x-road.eu"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{}, "GetHistory", getHistoryInputHeader, new global::Calculator.Xroad.Eu.Messages.HistoryRequest(request)));
            return ((global::Calculator.Xroad.Eu.Messages.HistoryResponse)(responseEnvelope.Body));
        }
        
        public virtual global::Calculator.Xroad.Eu.Messages.AddResponse Add(global::Calculator.Xroad.Eu.Variables request) {
            var addInputHeader = new global::Calculator.Xroad.Eu.Headers.AddInputHeader();
            addInputHeader.Client = _xteeCommand.Configuration.Client;
            addInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            addInputHeader.ProtocolVersion = this.ProtocolVersion;
            addInputHeader.Service = Service;
            addInputHeader.Service.ServiceCode = "Add";
            addInputHeader.Service.ServiceVersion = "v1";
            addInputHeader.UserId = _xteeCommand.Configuration.UserId;
            addInputHeader.Issue = _xteeCommand.Configuration.Issue;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("tns", "http://calculator.x-road.eu"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{}, "Add", addInputHeader, new global::Calculator.Xroad.Eu.Messages.AddRequest(request)));
            return ((global::Calculator.Xroad.Eu.Messages.AddResponse)(responseEnvelope.Body));
        }
        
        public virtual global::Calculator.Xroad.Eu.Messages.MultiplyResponse Multiply(global::Calculator.Xroad.Eu.Variables request) {
            var multiplyInputHeader = new global::Calculator.Xroad.Eu.Headers.MultiplyInputHeader();
            multiplyInputHeader.Client = _xteeCommand.Configuration.Client;
            multiplyInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            multiplyInputHeader.ProtocolVersion = this.ProtocolVersion;
            multiplyInputHeader.Service = Service;
            multiplyInputHeader.Service.ServiceCode = "Multiply";
            multiplyInputHeader.Service.ServiceVersion = "v1";
            multiplyInputHeader.UserId = _xteeCommand.Configuration.UserId;
            multiplyInputHeader.Issue = _xteeCommand.Configuration.Issue;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("tns", "http://calculator.x-road.eu"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{}, "Multiply", multiplyInputHeader, new global::Calculator.Xroad.Eu.Messages.MultiplyRequest(request)));
            return ((global::Calculator.Xroad.Eu.Messages.MultiplyResponse)(responseEnvelope.Body));
        }
        
        public virtual global::Calculator.Xroad.Eu.Messages.SubtractResponse Subtract(global::Calculator.Xroad.Eu.Variables request) {
            var subtractInputHeader = new global::Calculator.Xroad.Eu.Headers.SubtractInputHeader();
            subtractInputHeader.Client = _xteeCommand.Configuration.Client;
            subtractInputHeader.Id = Xtee.Core.Utils.StringUtils.GenerateNonce();
            subtractInputHeader.ProtocolVersion = this.ProtocolVersion;
            subtractInputHeader.Service = Service;
            subtractInputHeader.Service.ServiceCode = "Subtract";
            subtractInputHeader.Service.ServiceVersion = "v1";
            subtractInputHeader.UserId = _xteeCommand.Configuration.UserId;
            subtractInputHeader.Issue = _xteeCommand.Configuration.Issue;
            global::Xtee.Core.Envelope.ISoapEnvelope responseEnvelope = _xteeCommand.Execute(new global::Xtee.Core.Envelope.SoapEnvelope(new System.Xml.XmlQualifiedName("tns", "http://calculator.x-road.eu"), new System.Collections.Generic.List<System.Xml.XmlQualifiedName>{}, "Subtract", subtractInputHeader, new global::Calculator.Xroad.Eu.Messages.SubtractRequest(request)));
            return ((global::Calculator.Xroad.Eu.Messages.SubtractResponse)(responseEnvelope.Body));
        }
    }
}
